<?php

/** 
 * Remove um aluno
 */
function alunos_remove($id) {
	DAO::daoFactory(Aluno::TYPE)->remove($id);
}


/**
 * Autocomplete
 */
function alunos_autocomplete($string) {
	$matches = array();
	$query = db_select(Aluno::TYPE);

	$or = db_or();
	$or->condition(Aluno::TYPE . '.nome', '%' . db_like($string) . '%', 'LIKE');
	$or->condition(Aluno::TYPE . '.cpf',  '%' . db_like($string) . '%', 'LIKE');

	$query->condition($or);
	$return = $query
	->fields(Aluno::TYPE, array('nome','cpf'))
	->range(0, 10)
	->condition($or)
	->execute();

	foreach ($return as $user)
		$matches[$user->nome] = check_plain($user->nome);

	drupal_json_output($matches);
}